package com.junlaninfo.write;

import java.util.concurrent.*;

/**
 * Created by 辉 on 2020/9/8.
 */
public class MyExecutors {
    public static ExecutorService newFixedThreadPool(int coreSize, int maxSize, int queueSize) {
        return new ThreadPoolExecutor(coreSize, maxSize,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(queueSize),
                new MyrejectedExecutionHandler());
    }

    public static void main(String[] args) {
        ExecutorService executorService = MyExecutors.newFixedThreadPool(10, 15, 5);
        for (int i = 0; i < 100; i++) {
            final int finalI = i;

            executorService.execute(new Runnable() {
                public void run() {
                    try {
                        Thread.sleep(300);

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "..." + finalI);

                }
            });
        }
    }
}
